package com.drojian.demo1.test4;

import android.os.Bundle;
import android.widget.GridView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.drojian.demo.R;
import com.drojian.demo1.pojo.Fruit;

import java.util.ArrayList;
import java.util.List;

public class GridActivity extends AppCompatActivity {
    List<Fruit> datas = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.ui4_activity_grid);
        
        initData();

        GridView gridView2 = findViewById(R.id.gridView2);
        MyGridViewAdapter myGridViewAdapter = new MyGridViewAdapter(GridActivity.this,datas);
        gridView2.setAdapter(myGridViewAdapter);
    }

    private void initData() {
        for(int i = 0; i<8 ;i++){
            Fruit apple = new Fruit("apple",R.drawable.apple);
            datas.add(apple);
            Fruit banana = new Fruit("banana",R.drawable.banana);
            datas.add(banana);
            Fruit orange = new Fruit("orange",R.drawable.orange);
            datas.add(orange);
            Fruit watermelon = new Fruit("watermelon",R.drawable.watermelon);
            datas.add(watermelon);
            Fruit pear = new Fruit("pear",R.drawable.pear);
            datas.add(pear);
            Fruit pineapple = new Fruit("pineapple",R.drawable.pineapple);
            datas.add(pineapple);
            Fruit strawberry = new Fruit("strawberry",R.drawable.strawberry);
            datas.add(strawberry);
            Fruit cherry = new Fruit("cherry",R.drawable.cherry);
            datas.add(cherry);
            Fruit mango = new Fruit("mango",R.drawable.mango);
            datas.add(mango);

        }

    }
}